package cn.xq.pethome.shop1.controller;

import cn.xq.pethome.employee.domain.Employee;
import cn.xq.pethome.employee.query.EmployeeQuery;
import cn.xq.pethome.shop1.domain.Shop1;
import cn.xq.pethome.shop1.query.Shop1QUery;
import cn.xq.pethome.shop1.service.IShopService;
import cn.xq.pethome.utils.AjaxUtil;
import com.baomidou.mybatisplus.extension.service.IService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/shop1")
public class Shop1Controller {
    @Autowired
    private IShopService shopService;

    @GetMapping("/list")
    @ApiOperation(value = "查询所有顾客")
    public AjaxUtil fingall(){
        List<Shop1> fingall = shopService.fingall();
        return AjaxUtil.success().setData(fingall);
    }

    @PostMapping("/{id}")
    @ApiOperation(value = "根据id查询顾客")
    public AjaxUtil findone(@PathVariable("id") Long id){
        Shop1 fingone = shopService.fingone(id);
        return AjaxUtil.success().setMsg("查询成功").setData(fingone);
    }
    @DeleteMapping("/{id}")
    @ApiOperation(value = "根据id删除顾客")
    public AjaxUtil delete(@PathVariable("id") Long id){
        shopService.delete(id);
        return AjaxUtil.success().setMsg("删除成功");
    }

    @PostMapping("/pagelist")
    @ApiOperation(value = "高级查询")
    public AjaxUtil findquery(@RequestBody Shop1QUery shop1QUery ){
        try {
            List<Shop1> findquery = shopService.findquery(shop1QUery);
            //Long total=Long.parseLong("findquery.size()");
            Long fingquerycount = shopService.fingquerycount(shop1QUery);
            return  AjaxUtil.success().setTotal(fingquerycount).setData(findquery);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxUtil.error();
        }
    }
    @PutMapping("/")
    @ApiOperation(value = "增加与修改")
    public AjaxUtil save(@RequestBody Shop1 shop1){
        try {
            if(shop1.getId()==null){
                shopService.insert(shop1);
                return AjaxUtil.success().setMsg("添加成功");
            }else{
                shopService.update(shop1);
                return AjaxUtil.success().setMsg("修改失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return AjaxUtil.error();
    }
}
